<html>
<head><meta charset="utf-8"><title>Native frame definition · project-ffi-unwind · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/index.html">project-ffi-unwind</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Native.20frame.20definition.html">Native frame definition</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="178319895"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Native%20frame%20definition/near/178319895" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Native.20frame.20definition.html#178319895">(Oct 16 2019 at 19:16)</a>:</h4>
<p>For calling a function following the “native” platform ABI, there are often many constraints imposed by the platform. </p>
<p>For example, if the platform ABI is a C ABI, there is often the concept of a contiguous stack, with stack frames, which have to satisfy an ABI.</p>
<p>This causes problems, for example, when Go calls into C, it needs to copy its segmented stacks into a contiguous stack, which has some cost. </p>
<p>By “native” frames, I was referring to how the platform defines frames for its ABI. Same for unwinding, and the call ABI. Those are the constraints that must be satisfied when interfacing with the OS kernel, etc.</p>



<a name="178321407"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Native%20frame%20definition/near/178321407" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Native.20frame.20definition.html#178321407">(Oct 16 2019 at 19:36)</a>:</h4>
<p>Makes sense. I'm not sure what this is in reference to, though :)</p>



<a name="178324493"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Native%20frame%20definition/near/178324493" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> acfoltzer <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Native.20frame.20definition.html#178324493">(Oct 16 2019 at 20:15)</a>:</h4>
<p>I think this could come into play for trying to unwind frames that lack call frame information</p>



<a name="178324531"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Native%20frame%20definition/near/178324531" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> acfoltzer <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Native.20frame.20definition.html#178324531">(Oct 16 2019 at 20:15)</a>:</h4>
<p>we basically have a segmented stack on Lucet, though, and while it's tricky to write the CFI to wire up the pieces of the different stacks, it works without having to do any copying</p>



<a name="178362434"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Native%20frame%20definition/near/178362434" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Native.20frame.20definition.html#178362434">(Oct 17 2019 at 08:59)</a>:</h4>
<blockquote>
<p>I'm not sure what this is in reference to, though :)</p>
</blockquote>
<p>Oh sorry, this was me branching <span class="user-mention" data-user-id="237472">@acfoltzer</span> comment from the other thread into its own discussion: <a href="#narrow/stream/210922-wg-ffi-unwind/topic/lucent.20use.20case/near/178318996" title="#narrow/stream/210922-wg-ffi-unwind/topic/lucent.20use.20case/near/178318996">https://rust-lang.zulipchat.com/#narrow/stream/210922-wg-ffi-unwind/topic/lucent.20use.20case/near/178318996</a></p>
<blockquote>
<p>the one thing I'd point out based on your comments here is that the "native" frames in the Lucet use case are generated from Wasm, not Rust. I believe Weld generates their code from LLVM, so "native" for them also means non-Rust</p>
</blockquote>



<a name="178362659"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Native%20frame%20definition/near/178362659" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Native.20frame.20definition.html#178362659">(Oct 17 2019 at 09:02)</a>:</h4>
<p>So if we agree on what native frames are, then we just need to agree on what Rust frames are, and then we can see what's going on there.</p>



<a name="178362702"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Native%20frame%20definition/near/178362702" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Native.20frame.20definition.html#178362702">(Oct 17 2019 at 09:03)</a>:</h4>
<p>For example, if you use Rust to compile WASM and that WASM to emit a native frame, is that native frame a Rust frame of the same kind that if you just go from Rust to native on that platform ?</p>



<a name="178362740"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Native%20frame%20definition/near/178362740" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Native.20frame.20definition.html#178362740">(Oct 17 2019 at 09:03)</a>:</h4>
<p>Or if like weld, you just have LLVM-IR and emit a native frame, is that a Rust native frame ?</p>



<a name="178362799"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Native%20frame%20definition/near/178362799" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Native.20frame.20definition.html#178362799">(Oct 17 2019 at 09:04)</a>:</h4>
<p>I think that a reasonable way to say what Rust native frames are would be to say that "they are frames generated by the Rust toolchain"</p>



<a name="178362836"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Native%20frame%20definition/near/178362836" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Native.20frame.20definition.html#178362836">(Oct 17 2019 at 09:04)</a>:</h4>
<p>Since weld and lucet are different toolchains, the frames they generate aren't Rust frames.</p>



<a name="178362850"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Native%20frame%20definition/near/178362850" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Native.20frame.20definition.html#178362850">(Oct 17 2019 at 09:05)</a>:</h4>
<p>That is, if lucet wasm "unwinds", that exception should be foreign in Rust</p>



<a name="178362888"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Native%20frame%20definition/near/178362888" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Native.20frame.20definition.html#178362888">(Oct 17 2019 at 09:05)</a>:</h4>
<p>and if lucet Rust unwinds through a "lucet-wasm native frame" back into Rust, then the Rust panic should be foreign in the "lucet wasm native frame"</p>



<a name="178363021"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Native%20frame%20definition/near/178363021" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Native.20frame.20definition.html#178363021">(Oct 17 2019 at 09:07)</a>:</h4>
<p>However, I can imagine that for lucet's application it might make sense to allow those "lucet-wasm native frames" to handle Rust panics as non-foreign</p>



<a name="178398900"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Native%20frame%20definition/near/178398900" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> acfoltzer <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Native.20frame.20definition.html#178398900">(Oct 17 2019 at 16:42)</a>:</h4>
<p>Yep, you've got it right. "Rust frames" to me are only those frames for functions emitted by <code>rustc</code>; the fact that the Lucet and Weld compilers are implemented in Rust is incidental</p>
<blockquote>
<p>However, I can imagine that for lucet's application it might make sense to allow those "lucet-wasm native frames" to handle Rust panics as non-foreign</p>
</blockquote>
<p>This isn't in our future plans. The only reason the wasm frames might need to have more than just <code>.eh_frame</code> information is if we choose native unwinding as the means to support the Wasm exceptions proposal. In this case, Wasm would be treated as its own language for, e.g., the <code>exceptionClass</code> field in the ABI. If we needed to unwind from a Rust frame such that the Wasm frames would be able to catch it, we would use <code>_RaiseException</code> with a custom-made exception object rather than using a Rust panic</p>



<a name="178399065"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Native%20frame%20definition/near/178399065" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Native.20frame.20definition.html#178399065">(Oct 17 2019 at 16:45)</a>:</h4>
<p><span class="user-mention" data-user-id="237472">@acfoltzer</span> makes sense - Can those WASM exceptions unwinding out-of-wasm into rust ?</p>



<a name="178399136"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Native%20frame%20definition/near/178399136" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> acfoltzer <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Native.20frame.20definition.html#178399136">(Oct 17 2019 at 16:46)</a>:</h4>
<p>they would be able to, but again this is a double-hypothetical that 1. the Wasm exceptions proposal is accepted and 2. we choose to use native unwinding to implement it</p>



<a name="178399212"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Native%20frame%20definition/near/178399212" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> acfoltzer <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Native.20frame.20definition.html#178399212">(Oct 17 2019 at 16:46)</a>:</h4>
<p>but one could imagine <code>Rust -&gt; Wasm (catches) -&gt; Rust -&gt; Wasm (throws)</code></p>



<a name="178399292"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Native%20frame%20definition/near/178399292" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> acfoltzer <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Native.20frame.20definition.html#178399292">(Oct 17 2019 at 16:47)</a>:</h4>
<p>what I <em>can't</em> imagine happening is a Wasm exception unwinding out to the outermost frames outside the initial call to the guest, since that would be analogous to an exception unwinding beyond the entrypoint of a normal program</p>



<a name="178399425"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Native%20frame%20definition/near/178399425" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> acfoltzer <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Native.20frame.20definition.html#178399425">(Oct 17 2019 at 16:48)</a>:</h4>
<p>we would always want to catch that case and return a <code>GuestUnhandledException</code> error to the runtime user or something along those lines</p>



<a name="178400720"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Native%20frame%20definition/near/178400720" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Native.20frame.20definition.html#178400720">(Oct 17 2019 at 17:02)</a>:</h4>
<blockquote>
<p>but one could imagine Rust -&gt; Wasm (catches) -&gt; Rust -&gt; Wasm (throws)</p>
</blockquote>
<p>That's what I was referring to. This would require supporting unwinding Rust frames with foreign exceptions</p>



<a name="178400774"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Native%20frame%20definition/near/178400774" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Native.20frame.20definition.html#178400774">(Oct 17 2019 at 17:03)</a>:</h4>
<p>I'm going to take a look at the WASM exception proposal, this might be relevant for WASI</p>



<a name="178713063"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Native%20frame%20definition/near/178713063" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Native.20frame.20definition.html#178713063">(Oct 22 2019 at 00:40)</a>:</h4>
<p><span class="user-mention" data-user-id="237472">@acfoltzer</span> <span class="user-mention" data-user-id="116009">@nikomatsakis</span> <span class="user-mention" data-user-id="132920">@gnzlbg</span> </p>
<p>I'm finally reading Niko's RFC draft, and it's pushing me towards avoiding the phrase "native frames" entirely. I think we should refer to "Rust frames" and "foreign frames", which is more explicit and lines up with the F for "foreign" in "cross-FFI unwinding".</p>



<a name="178713089"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Native%20frame%20definition/near/178713089" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Native.20frame.20definition.html#178713089">(Oct 22 2019 at 00:41)</a>:</h4>
<p>(One thing that led me to this conclusion is that in many cases we've been saying "native" where we mean "foreign", and those are _very odd_ words to treat synonymously!)</p>



<a name="178713112"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Native%20frame%20definition/near/178713112" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Native.20frame.20definition.html#178713112">(Oct 22 2019 at 00:41)</a>:</h4>
<p>"Native" as a descriptor should, I think, only be used to refer to the "native unwinding mechanism" or other details of the platform-provided ABI.</p>



<a name="178713172"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Native%20frame%20definition/near/178713172" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Native.20frame.20definition.html#178713172">(Oct 22 2019 at 00:42)</a>:</h4>
<p>("Foreign" also has a connection to the Itanium ABI spec, which refers to "foreign exceptions.")</p>



<a name="179270994"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Native%20frame%20definition/near/179270994" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Native.20frame.20definition.html#179270994">(Oct 28 2019 at 20:15)</a>:</h4>
<blockquote>
<p>I'm finally reading Niko's RFC draft, and it's pushing me towards avoiding the phrase "native frames" entirely. I think we should refer to "Rust frames" and "foreign frames", which is more explicit and lines up with the F for "foreign" in "cross-FFI unwinding".</p>
</blockquote>
<p>seems good, btw</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>